home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacOS 8 Resources / Developer Tools / Mac OS 8 Interfaces & Libraries / Interfaces / AIncludes / Synchronization.a < prev    next >
Encoding:
Text File  |  1996-05-01  |  9.7 KB  |  432 lines  |  [TEXT/MPS ]

  1. ;
  2. ;    File:        Synchronization.a
  3. ;
  4. ;    Contains:    Synchronization Interfaces
  5. ;
  6. ;    Version:    Technology:    System 8
  7. ;                Release:    Universal Interfaces 3.0d3 on Copland DR1
  8. ;
  9. ;    Copyright:    © 1984-1996 by Apple Computer, Inc.  All rights reserved.
  10. ;
  11. ;    Bugs?:        If you find a problem with this file, send the file and version
  12. ;                information (from above) and the problem description to:
  13. ;
  14. ;                    Internet:    apple.bugs@applelink.apple.com
  15. ;                    AppleLink:    APPLE.BUGS
  16. ;
  17. ;
  18.     IF &TYPE('__SYNCHRONIZATION__') = 'UNDEFINED' THEN
  19. __SYNCHRONIZATION__ SET 1
  20.  
  21.     IF &TYPE('__TYPES__') = 'UNDEFINED' THEN
  22.     include 'Types.a'
  23.     ENDIF
  24.     IF &TYPE('__KERNEL__') = 'UNDEFINED' THEN
  25.     include 'Kernel.a'
  26.     ENDIF
  27.     IF FOR_SYSTEM8_PREEMPTIVE THEN
  28. ;  Note:  Lock, ReadWriteLock, and CountingSemaphore data structures must be LONG WORD ALIGNED in memory!
  29. Lock                    RECORD 0
  30. theInfo                     ds.l    2                ; offset: $0 (0)
  31. sizeof                     EQU *                    ; size:   $8 (8)
  32.                         ENDR
  33. ; typedef struct Lock *                    LockPtr
  34.  
  35. ReadWriteLock            RECORD 0
  36. theInfo                     ds.l    5                ; offset: $0 (0)
  37. sizeof                     EQU *                    ; size:   $14 (20)
  38.                         ENDR
  39. ; typedef struct ReadWriteLock *        ReadWriteLockPtr
  40.  
  41. CountingSemaphore        RECORD 0
  42. theInfo                     ds.l    6                ; offset: $0 (0)
  43. sizeof                     EQU *                    ; size:   $18 (24)
  44.                         ENDR
  45. ; typedef struct CountingSemaphore *    CountingSemaphorePtr
  46.  
  47. ; typedef OptionBits                     LockOptions
  48.  
  49.  
  50. kLockDisablesSwis                EQU        $00000001            ; disable software interrupts while locked
  51. kLockAdjustsPriorities            EQU        $00000002            ; lock prevents priority inversion
  52. kLockDisablesCompletionRoutines    EQU        $00000004            ; disable software interrupts and system 7 completion routines while locked
  53. ; typedef void *                        InterruptState
  54.  
  55. ;
  56. ; Simple lock routines
  57. ; Locks may be created with the kLockDisablesSwis and/or kLockDisablesCompletionRoutines options,
  58. ; but no others.
  59. ;
  60. ;
  61. ; extern OSStatus CreateLock(Lock *theLock, LockOptions theOptions)
  62. ;
  63.     IF GENERATINGCFM THEN
  64.         IMPORT_CFM_FUNCTION CreateLock
  65.     ENDIF
  66.  
  67. ;
  68. ; extern OSStatus DeleteLock(Lock *theLock)
  69. ;
  70.     IF GENERATINGCFM THEN
  71.         IMPORT_CFM_FUNCTION DeleteLock
  72.     ENDIF
  73.  
  74. ;
  75. ; extern OSStatus BeginLockedSection(Lock *theLock)
  76. ;
  77.     IF GENERATINGCFM THEN
  78.         IMPORT_CFM_FUNCTION BeginLockedSection
  79.     ENDIF
  80.  
  81. ;
  82. ; extern OSStatus TryBeginLockedSection(Lock *theLock)
  83. ;
  84.     IF GENERATINGCFM THEN
  85.         IMPORT_CFM_FUNCTION TryBeginLockedSection
  86.     ENDIF
  87.  
  88. ;
  89. ; extern OSStatus EndLockedSection(Lock *theLock)
  90. ;
  91.     IF GENERATINGCFM THEN
  92.         IMPORT_CFM_FUNCTION EndLockedSection
  93.     ENDIF
  94.  
  95. ;
  96. ; extern Boolean IsLockedSectionHeld(Lock *theLock)
  97. ;
  98.     IF GENERATINGCFM THEN
  99.         IMPORT_CFM_FUNCTION IsLockedSectionHeld
  100.     ENDIF
  101.  
  102. ;
  103. ; Reader/writer lock routines
  104. ; ReadWriteLocks may be created with the kLockDisablesSwis, kLockDisablesCompletionRoutines,
  105. ; and/or kLockAdjustsPriorities options.
  106. ;
  107. ;
  108. ; extern OSStatus CreateReadWriteLock(ReadWriteLock *theReadWriteLock, LockOptions theOptions)
  109. ;
  110.     IF GENERATINGCFM THEN
  111.         IMPORT_CFM_FUNCTION CreateReadWriteLock
  112.     ENDIF
  113.  
  114. ;
  115. ; extern OSStatus DeleteReadWriteLock(ReadWriteLock *theReadWriteLock)
  116. ;
  117.     IF GENERATINGCFM THEN
  118.         IMPORT_CFM_FUNCTION DeleteReadWriteLock
  119.     ENDIF
  120.  
  121. ;
  122. ; extern OSStatus BeginReadLockedSection(ReadWriteLock *theReadWriteLock)
  123. ;
  124.     IF GENERATINGCFM THEN
  125.         IMPORT_CFM_FUNCTION BeginReadLockedSection
  126.     ENDIF
  127.  
  128. ;
  129. ; extern OSStatus TryBeginReadLockedSection(ReadWriteLock *theReadWriteLock)
  130. ;
  131.     IF GENERATINGCFM THEN
  132.         IMPORT_CFM_FUNCTION TryBeginReadLockedSection
  133.     ENDIF
  134.  
  135. ;
  136. ; extern OSStatus EndReadLockedSection(ReadWriteLock *theReadWriteLock)
  137. ;
  138.     IF GENERATINGCFM THEN
  139.         IMPORT_CFM_FUNCTION EndReadLockedSection
  140.     ENDIF
  141.  
  142. ;
  143. ; extern OSStatus BeginWriteLockedSection(ReadWriteLock *theReadWriteLock)
  144. ;
  145.     IF GENERATINGCFM THEN
  146.         IMPORT_CFM_FUNCTION BeginWriteLockedSection
  147.     ENDIF
  148.  
  149. ;
  150. ; extern OSStatus TryBeginWriteLockedSection(ReadWriteLock *theReadWriteLock)
  151. ;
  152.     IF GENERATINGCFM THEN
  153.         IMPORT_CFM_FUNCTION TryBeginWriteLockedSection
  154.     ENDIF
  155.  
  156. ;
  157. ; extern OSStatus EndWriteLockedSection(ReadWriteLock *theReadWriteLock)
  158. ;
  159.     IF GENERATINGCFM THEN
  160.         IMPORT_CFM_FUNCTION EndWriteLockedSection
  161.     ENDIF
  162.  
  163. ;
  164. ; extern OSStatus ChangeWriteLockToReadLock(ReadWriteLock *theReadWriteLock)
  165. ;
  166.     IF GENERATINGCFM THEN
  167.         IMPORT_CFM_FUNCTION ChangeWriteLockToReadLock
  168.     ENDIF
  169.  
  170. ;
  171. ; extern Boolean IsReadLockedSectionHeld(ReadWriteLock *theReadWriteLock)
  172. ;
  173.     IF GENERATINGCFM THEN
  174.         IMPORT_CFM_FUNCTION IsReadLockedSectionHeld
  175.     ENDIF
  176.  
  177. ;
  178. ; extern Boolean IsWriteLockedSectionHeld(ReadWriteLock *theReadWriteLock)
  179. ;
  180.     IF GENERATINGCFM THEN
  181.         IMPORT_CFM_FUNCTION IsWriteLockedSectionHeld
  182.     ENDIF
  183.  
  184. ;
  185. ; extern ItemCount GetReadWriteLockReaderCount(ReadWriteLock *theReadWriteLock)
  186. ;
  187.     IF GENERATINGCFM THEN
  188.         IMPORT_CFM_FUNCTION GetReadWriteLockReaderCount
  189.     ENDIF
  190.  
  191. ;
  192. ; extern TaskID GetReadWriteLockWriterID(ReadWriteLock *theReadWriteLock)
  193. ;
  194.     IF GENERATINGCFM THEN
  195.         IMPORT_CFM_FUNCTION GetReadWriteLockWriterID
  196.     ENDIF
  197.  
  198. ;
  199. ; Counting semaphore routines
  200. ; CountingSemaphores currently have no options.
  201. ;
  202. ;
  203. ; extern OSStatus CreateCountingSemaphore(CountingSemaphore *theCountingSemaphore, LockOptions theOptions, SInt32 initialCount, SInt32 maximumCount)
  204. ;
  205.     IF GENERATINGCFM THEN
  206.         IMPORT_CFM_FUNCTION CreateCountingSemaphore
  207.     ENDIF
  208.  
  209. ;
  210. ; extern OSStatus DeleteCountingSemaphore(CountingSemaphore *theCountingSemaphore)
  211. ;
  212.     IF GENERATINGCFM THEN
  213.         IMPORT_CFM_FUNCTION DeleteCountingSemaphore
  214.     ENDIF
  215.  
  216. ;
  217. ; extern OSStatus WaitForCountingSemaphore(CountingSemaphore *theCountingSemaphore)
  218. ;
  219.     IF GENERATINGCFM THEN
  220.         IMPORT_CFM_FUNCTION WaitForCountingSemaphore
  221.     ENDIF
  222.  
  223. ;
  224. ; extern OSStatus SignalCountingSemaphore(CountingSemaphore *theCountingSemaphore)
  225. ;
  226.     IF GENERATINGCFM THEN
  227.         IMPORT_CFM_FUNCTION SignalCountingSemaphore
  228.     ENDIF
  229.  
  230. ;
  231. ; extern SInt32 GetCountingSemaphoreCount(CountingSemaphore *theCountingSemaphore)
  232. ;
  233.     IF GENERATINGCFM THEN
  234.         IMPORT_CFM_FUNCTION GetCountingSemaphoreCount
  235.     ENDIF
  236.  
  237. ;
  238. ; extern SInt32 GetCountingSemaphoreMaxCount(CountingSemaphore *theCountingSemaphore)
  239. ;
  240.     IF GENERATINGCFM THEN
  241.         IMPORT_CFM_FUNCTION GetCountingSemaphoreMaxCount
  242.     ENDIF
  243.  
  244. ;
  245. ; extern ItemCount GetCountingSemaphoreWaiterCount(CountingSemaphore *theCountingSemaphore)
  246. ;
  247.     IF GENERATINGCFM THEN
  248.         IMPORT_CFM_FUNCTION GetCountingSemaphoreWaiterCount
  249.     ENDIF
  250.  
  251. ;
  252. ; Interrupt enabling and disabling.  ** MAY ONLY BE CALLED FROM PRIVILEGED CODE!!! **
  253. ; Use very sparingly.
  254. ;
  255. ;
  256. ; extern InterruptState DisableInterrupts(void )
  257. ;
  258.     IF GENERATINGCFM THEN
  259.         IMPORT_CFM_FUNCTION DisableInterrupts
  260.     ENDIF
  261.  
  262. ;
  263. ; extern void RestoreInterrupts(InterruptState theState)
  264. ;
  265.     IF GENERATINGCFM THEN
  266.         IMPORT_CFM_FUNCTION RestoreInterrupts
  267.     ENDIF
  268.  
  269. ;
  270. ; Atomic operations on 8-, 16-, and 32-bit entities.
  271. ; ** OPERATIONS THAT CROSS WORD (32-BIT) BOUNDARIES WILL FAIL!!! **
  272. ;
  273. ;
  274. ; extern Boolean CompareAndSwapAligned(UInt32 oldValue, UInt32 newValue, UInt32 *theValue)
  275. ;
  276.     IF GENERATINGCFM THEN
  277.         IMPORT_CFM_FUNCTION CompareAndSwapAligned
  278.     ENDIF
  279.  
  280. ;  Note: TestAndSet uses PPC bit ordering, zero is the high bit, and theBit ranges from 0 - FFFFFFFF.
  281. ;
  282. ; extern Boolean TestAndSet(UInt32 theBit, UInt8 *startAddress)
  283. ;
  284.     IF GENERATINGCFM THEN
  285.         IMPORT_CFM_FUNCTION TestAndSet
  286.     ENDIF
  287.  
  288. ;
  289. ; extern SInt8 IncrementAtomic8(SInt8 *value)
  290. ;
  291.     IF GENERATINGCFM THEN
  292.         IMPORT_CFM_FUNCTION IncrementAtomic8
  293.     ENDIF
  294.  
  295. ;
  296. ; extern SInt8 DecrementAtomic8(SInt8 *value)
  297. ;
  298.     IF GENERATINGCFM THEN
  299.         IMPORT_CFM_FUNCTION DecrementAtomic8
  300.     ENDIF
  301.  
  302. ;
  303. ; extern SInt8 AddAtomic8(SInt32 amount, SInt8 *value)
  304. ;
  305.     IF GENERATINGCFM THEN
  306.         IMPORT_CFM_FUNCTION AddAtomic8
  307.     ENDIF
  308.  
  309. ;
  310. ; extern UInt8 BitAndAtomic8(UInt32 mask, UInt8 *value)
  311. ;
  312.     IF GENERATINGCFM THEN
  313.         IMPORT_CFM_FUNCTION BitAndAtomic8
  314.     ENDIF
  315.  
  316. ;
  317. ; extern UInt8 BitOrAtomic8(UInt32 mask, UInt8 *value)
  318. ;
  319.     IF GENERATINGCFM THEN
  320.         IMPORT_CFM_FUNCTION BitOrAtomic8
  321.     ENDIF
  322.  
  323. ;
  324. ; extern UInt8 BitXorAtomic8(UInt32 mask, UInt8 *value)
  325. ;
  326.     IF GENERATINGCFM THEN
  327.         IMPORT_CFM_FUNCTION BitXorAtomic8
  328.     ENDIF
  329.  
  330. ;
  331. ; extern SInt16 IncrementAtomic16Aligned(SInt16 *theValue)
  332. ;
  333.     IF GENERATINGCFM THEN
  334.         IMPORT_CFM_FUNCTION IncrementAtomic16Aligned
  335.     ENDIF
  336.  
  337. ;
  338. ; extern SInt16 DecrementAtomic16Aligned(SInt16 *theValue)
  339. ;
  340.     IF GENERATINGCFM THEN
  341.         IMPORT_CFM_FUNCTION DecrementAtomic16Aligned
  342.     ENDIF
  343.  
  344. ;
  345. ; extern SInt16 AddAtomic16Aligned(SInt32 theAmount, SInt16 *theValue)
  346. ;
  347.     IF GENERATINGCFM THEN
  348.         IMPORT_CFM_FUNCTION AddAtomic16Aligned
  349.     ENDIF
  350.  
  351. ;
  352. ; extern UInt16 BitAndAtomic16Aligned(UInt32 theMask, UInt16 *theValue)
  353. ;
  354.     IF GENERATINGCFM THEN
  355.         IMPORT_CFM_FUNCTION BitAndAtomic16Aligned
  356.     ENDIF
  357.  
  358. ;
  359. ; extern UInt16 BitOrAtomic16Aligned(UInt32 theMask, UInt16 *theValue)
  360. ;
  361.     IF GENERATINGCFM THEN
  362.         IMPORT_CFM_FUNCTION BitOrAtomic16Aligned
  363.     ENDIF
  364.  
  365. ;
  366. ; extern UInt16 BitXorAtomic16Aligned(UInt32 theMask, UInt16 *theValue)
  367. ;
  368.     IF GENERATINGCFM THEN
  369.         IMPORT_CFM_FUNCTION BitXorAtomic16Aligned
  370.     ENDIF
  371.  
  372. ;
  373. ; extern SInt32 IncrementAtomicAligned(SInt32 *theValue)
  374. ;
  375.     IF GENERATINGCFM THEN
  376.         IMPORT_CFM_FUNCTION IncrementAtomicAligned
  377.     ENDIF
  378.  
  379. ;
  380. ; extern SInt32 DecrementAtomicAligned(SInt32 *theValue)
  381. ;
  382.     IF GENERATINGCFM THEN
  383.         IMPORT_CFM_FUNCTION DecrementAtomicAligned
  384.     ENDIF
  385.  
  386. ;
  387. ; extern SInt32 AddAtomicAligned(SInt32 theAmount, SInt32 *theValue)
  388. ;
  389.     IF GENERATINGCFM THEN
  390.         IMPORT_CFM_FUNCTION AddAtomicAligned
  391.     ENDIF
  392.  
  393. ;
  394. ; extern UInt32 BitAndAtomicAligned(UInt32 theMask, UInt32 *theValue)
  395. ;
  396.     IF GENERATINGCFM THEN
  397.         IMPORT_CFM_FUNCTION BitAndAtomicAligned
  398.     ENDIF
  399.  
  400. ;
  401. ; extern UInt32 BitOrAtomicAligned(UInt32 theMask, UInt32 *theValue)
  402. ;
  403.     IF GENERATINGCFM THEN
  404.         IMPORT_CFM_FUNCTION BitOrAtomicAligned
  405.     ENDIF
  406.  
  407. ;
  408. ; extern UInt32 BitXorAtomicAligned(UInt32 theMask, UInt32 *theValue)
  409. ;
  410.     IF GENERATINGCFM THEN
  411.         IMPORT_CFM_FUNCTION BitXorAtomicAligned
  412.     ENDIF
  413.  
  414. ;  Atomic primitives for singly linked list manipulation.
  415. ;
  416. ; extern void PushListElementAtomic(void *theListHead, void *theListElement, UInt32 theLinkOffset)
  417. ;
  418.     IF GENERATINGCFM THEN
  419.         IMPORT_CFM_FUNCTION PushListElementAtomic
  420.     ENDIF
  421.  
  422. ;
  423. ; extern void *PopListElementAtomic(void *theListHead, UInt32 theLinkOffset)
  424. ;
  425.     IF GENERATINGCFM THEN
  426.         IMPORT_CFM_FUNCTION PopListElementAtomic
  427.     ENDIF
  428.  
  429.     ENDIF
  430.     ENDIF ; __SYNCHRONIZATION__ 
  431.  
  432.